﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.RemoteCtrls.Services
{
    public static class LocalizationProvider
    {
        public static string GetLocalizedString(string key)
        {
            var assembly = Assembly.GetExecutingAssembly();

            var resourceNames = assembly.GetManifestResourceNames();
            var assemblyName = assembly.GetName();
            var resourceName = assemblyName.Name + ".Resources.lang.codelangdic";

            string valueName = key;

            var isExisting = resourceNames.Any(item => item.Contains(resourceName));

            if (isExisting)
            {
                var resourceManager = new ResourceManager(resourceName, assembly);

                var value = resourceManager.GetString(key, System.Threading.Thread.CurrentThread.CurrentCulture);
                if (!String.IsNullOrWhiteSpace(value))
                {
                    valueName = value;
                }
            }

            return valueName;
        }
    }
}
